/*
 * =====================================================================================
 *
 *       Filename:  atomic.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/10/2012 02:51:33 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef ATOMIC_H
#define ATOMIC_H
namespace inm
{
	namespace concurrency
	{
		template<typename T>
		class AtomicIntegerT
		{//just for increment and decrement now 
		//not override operator ++ -- << ,instead of increment decrement getValue. So people can realize AtomicInt is a class.
			public:
				AtomicIntegerT():val_(0){}
				AtomicIntegerT(int val):val_(val){}
				T increment()
				{
					return __sync_add_and_fetch(&val_,1);
				}
				T decrement()
				{
					return __sync_sub_and_fetch(&val_,1);
				}
				T getValue()
				{
					return val_;
				}
			private:
				T val_;
		};
				
	};
	typedef concurrency::AtomicIntegerT<int> AtomicInt;
	typedef concurrency::AtomicIntegerT<short> AtomicShort;
};
#endif //ATOMIC_H
